<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<%@ include file="/pages/inc/taglibs.jsp"%>
</head>
<body style="padding-top: 50px">
	<div class="container filter">
		<input type="button" value="增加" data-target="#addmodal"
			data-toggle="modal" onclick="openAddIntangible()"> <input
			type="button" value="修改" onclick="openEditIntangible()"
			data-target="#addmodal" data-toggle="modal"> <input
			type="button" value="删除" onclick="deleteIntangible()">
		<div id="intangibleList">

			<table id="example" class="table table-striped table-bordered"
				cellspacing="0" width="100%">
				<thead>
					<tr>
						<th></th>
						<th>编号</th>
						<th>资产名称</th>
						<th>使用（折旧）年限</th>
						<th>记账时间</th>
						<th>原值（计税基础）</th>
						<th>用途</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th></th>
						<th>编号</th>
						<th>资产名称</th>
						<th>使用（折旧）年限</th>
						<th>记账时间</th>
						<th>原值（计税基础）</th>
						<th>用途</th>
					</tr>
				</tfoot>
				<tbody>
					<c-rt:forEach items="${intangibleList}" var="intangible">
						<tr>
							<td><input type="checkbox" name="intangibleCheckbox"
								value="${intangible.id}"></td>
							<td><a ref="#">${intangible.intangibleNo}</a></td>
							<td>${intangible.intangibleName}</td>
							<td>${intangible.depreciationYear}</td>
							<td>${intangible.createTime}</td>
							<td>${intangible.originalValue}</td>
							<td>${intangible.purpose}</td>
						</tr>
					</c-rt:forEach>

				</tbody>
			</table>
		</div>
	</div>
	<div id="addmodal" class="modal fade">
		<div class="modal-dialog modal-lg">
			<div class="container newproject">
				<div class="modal-content">
					<div class="modal-header">
						<h4 class="modal-title">无形资产管理</h4>
					</div>
					<div class="modal-body">
						<form id="installationForm" class="form-horizontal">
							<input type="hidden" value="${intangible.id}" id="intangibleId">
							<div class="tab-content">
								<!-- First tab -->
								<div class="tab-pane active" id="basic-tab">
									<div class="form-group">
										<div>
											<label for="intangibleNo">编号：</label>
										</div>
										<div class="col-xs-10">
											<input type="text" class="form-control" id="intangibleNo">
										</div>
									</div>
									<div class="form-group">
										<div>
											<label for="intangibleName">资产名称：</label>
										</div>
										<div class="col-xs-10">
											<input type="text" class="form-control" id="intangibleName">
										</div>
									</div>
									<div class="form-group">
										<div>
											<label for="depreciationYear">使用年限:</label>
										</div>
										<div class="col-xs-10">
											<input type="text" id="depreciationYear">
										</div>
									</div>
									<div class="form-group">
										<div>
											<label for="originalValue">原值:</label>
										</div>
										<div class="col-xs-10">
											<input type="text" id="originalValue">
										</div>
									</div>

									<div class="form-group">
										<div>
											<label for="depreciationMethod">折旧方法：</label>
										</div>
										<div class="col-xs-10">
											<select id="depreciationMethod">
												<option value="1">直线折旧法</option>
												<option value="2">加速折旧法</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<div>
											<label for="purpose">用途:</label>
										</div>
										<div class="col-xs-10">
											<input type="text" id="purpose">
										</div>
									</div>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal"
							onclick="saveEmployee()">提交</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		function openAddIntangible() {
			$.ajax({
				url : "<c:url value='/company/intangible/addView' />",
				data : {},
				type : 'POST',
				dataType : 'html',
				success : function(data) {
					$("#addmodal").html("");
					$("#addmodal").html(data);
				},
				error : function(data) {
					alert("error");
				}
			});
		}

		function openEditIntangible() {
			if ($('input[name="intangibleCheckbox"]:checked').length != 1) {
				alert("修改只能选择一条记录！");
				return false;
			}
			var id = $('input[name="intangibleCheckbox"]:checked').val();
			$.ajax({
				url : "<c:url value='/company/intangible/editView' />",
				data : {
					id : id
				},
				type : 'POST',
				dataType : 'html',
				success : function(data) {
					$("#addmodal").html("");
					$("#addmodal").html(data);
				},
				error : function(data) {
					alert("error");
				}
			});
		}
		function saveIntangible() {
			var json = {};
			json.id = $("#intangibleId").val();
			json.intangibleNo = $("#intangibleNo").val();
			json.intangibleName = $("#intangibleName").val();
			json.depreciationYear = $("#depreciationYear").val();
			json.originalValue = $("#originalValue").val();
			json.purpose = $("#purpose").val();
			$.ajax({
				url : "<c:url value='/company/intangible/save' />",
				type : 'POST',
				dataType : 'json',
				data : json,
				success : function(data) {
					query();
				},
				error : function(data) {
					alert("error");
				}
			});
		}
		function deleteIntangible() {
			var ids = "";
			$('input[name="intangibleCheckbox"]:checked').each(function() {
				ids += $(this).val() + ",";
				//alert($(this).val()); 
			});
			var json = {};
			json.ids = ids;
			$.ajax({
				url : "<c:url value='/company/intangible/delete' />",
				type : 'POST',
				dataType : "json",
				data : json,
				success : function(data) {
					query();
				},
				error : function(data) {
					alert("error");
				}
			});
		}

		function query() {
			$.ajax({
				url : "<c:url value='/company/intangible/list' />",
				data : {},
				type : 'POST',
				dataType : 'html',
				success : function(data) {
					$("#intangibleList").html("");
					$("#intangibleList").html(data);
				},
				error : function(data) {
					alert("error");
				}
			});
		}
	</script>
</body>
</html>